package com.gs.disk.modules.headImgAndWallper.controller.admin;

import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.gs.entity.GeneralPage;
import com.gs.entity.R;
import com.gs.disk.modules.headImgAndWallper.dto.APairResourceDto;
import com.gs.disk.modules.headImgAndWallper.service.admin.AdminAPairResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("disk/admin/doubleResource")
@Api(tags = "后台套图管理")
@ApiSort(5)
public class AdminAPairResourceController {

    @Resource
    private AdminAPairResourceService service;

    @GetMapping("list")
    @ApiOperation("资源列表")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "分类id", name = "categoryId")
    })
//    @Cacheable(value = "list", keyGenerator = "myKeyGenerator")
    public R<GeneralPage<APairResourceDto>> list(@RequestParam(required = false) Long categoryId,
                                                 @RequestParam Long page,
                                                 @RequestParam Long limit) {
        GeneralPage<APairResourceDto> dto = service.list(categoryId, page, limit);
        return R.ok(dto);
    }

    @PostMapping("upload")
    @ApiOperation("上传资源")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "套图分类id", name = "categoryId"),
            @ApiImplicitParam(value = "头像图片id", name = "headImgId"),
            @ApiImplicitParam(value = "背景图", name = "backgroundImgId"),
            @ApiImplicitParam(value = "签名", name = "keyWord"),
            @ApiImplicitParam(value = "昵称", name = "nickname"),
    })
    public R uploadAPairResource(@RequestParam Long categoryId,
                                 @RequestParam Long headImgId,
                                 @RequestParam Long backgroundImgId,
                                 @RequestParam String keyWord,
                                 @RequestParam String nickname) {
        service.uploadAPairResource(categoryId, headImgId, backgroundImgId, keyWord, nickname);
        return R.ok();
    }

    @DeleteMapping("delete/{id}")
    public R delete(@PathVariable Long id) {
        service.delete(id);
        return R.ok();
    }


}
